<?php

include("classes/include.php");

session_start();

if(isset($_POST['numUti']))
{
$etu = new Etudiant($_POST['numUti']);
	
	$etu->enleverEtudiant();
	
	header("Location: etudiant.php");
}

if(isset($_POST['dateVisiteEtu']))
{
	$numUtilisateur = $_SESSION['utilisateur']->getNumUtilisateur();
		
	$recupEtudiantTuteur = new RequeteSQL("SELECT * FROM etudiant WHERE etu_tuteur = ".$numUtilisateur);
		
	$recupEtudiantTuteur->executeQuery();
	
	while($ligneEtu = $recupEtudiantTuteur->fetch())
	{
		if(isset($_POST[$ligneEtu['etu_id']]))
		{
			$dateVisite = $_POST[$ligneEtu['etu_id']];
			
			$reqUpdate = new RequeteSQL("UPDATE stage SET sta_date_visite = str_to_date('".$dateVisite."','%d/%m/%Y') WHERE sta_num_etudiant = ".$ligneEtu['etu_id']);
			$reqUpdate->executeEcriture();
			
			$reqInsert = new RequeteSQL("INSERT INTO agenda VALUES('',
															".$ligneEtu['etu_num_etudiant'].",
															str_to_date('".$dateVisite."','%d/%m/%Y'),
															'Visite entreprise')");
			$reqInsert->executeEcriture();
		}
	}
}

header("Location: etudiant.php");
	?>